Repository navigation
Model M (D3D12): hoist 8-byte base alignment masks in post_tf (-41.3 us on Windows AMD DX12, byte-identical) - #296
phantoslayer21 wants to merge 5 commits into
Conversation
…us on Windows AMD DX12, byte-identical)
…xposure is not 1 (-0.11 ms at pi = 2, byte-identical) On the staged native D3D12 route with a pre-exposure other than 1, the post_tf kernels (post_tf_f32_p12_diet_vsit, post_tf4_dl_*, pmo/post_tf_*_mo) now apply the scale_rgb multiply in their own store (native_scale's values, including the exact repair of a flushed tiny product), so the separate scale_rgb launch is gone. pi = 1, raw / direct / Model L routes and the interop output copy are untouched. WG_SCALE_FOLD=0 (runtime option scale_fold=0) brings the launch back. Windows AMD DX12 (RX 9070 XT, 1706x960 -> 2560x1440, 8 interleaved ABBA rounds, medians): pi = 2.0 frame span 2333 -> 2222 us (-111 us), kernel profile sum 2318 -> 2202 us (scale_rgb 128 -> 0 us, post_tf +10 us); pi = 1.0 unchanged (span -2 us, profile sum -2.5 us; post_tf keeps 85 VGPRs, 30336 B LDS). Output, history and every named buffer are byte-identical to the unfolded sequence and to v0.6.5 for pi in 1, 2, 0.7, 1e-3, 1e4, 1e38 and a mixed-pi stream, with +-0, denormal, huge, Inf and NaN colour pixels, on the post_tf, post_tf4, native-AA and motion-at-output-resolution routes.
Implement five bit-exact Model M D3D12 optimizations for gfx1201: - T1.1: hoist scalar alignment mask in post_tf history_cr_span (4 -> 0 v_and_b32 -8) and drop WG_LD_A16 per-VGPR masking on swin_block_c64_nc (17 -> 0 v_and_b32 -16) and dec1_dec0 (11 -> 0) while preserving all buffer_load_b128. - T1.2: port all 7 POST_OUT==3 bit-exact optimizations to POST_OUT==0 (pd_stage_fetch hoisting, unrolled gather + gather_zero_opq, 2-chain rh_code, 2x QuadReadAcrossX display LDS store + k==0 hsum skip, hoisted h_src/h_dst + pd_vsplit, WG_PT_SMALL/WG_PT_INF, and pi==1 vs pi!=1 body specialization). - T1.3: add 256 KB FP16 decode LUT (f16lut_build_dec) for staged POST_OUT==0 (output_filter=original), overlapped with input_encoder via unordered_next(), toggleable with WG_M_POST_LUT=0. - T1.5: drop input_encoder from 103 -> 95 VGPRs (0 scratch, 10 KB lane-private LDS -> 4 WGs/CU) via A-fragment streaming and per-lane LDS parking, plus WaveActiveAnyTrue(ec > 32752.0f) guard on the second wg_log2. - T1.8: overlap color_divide with exposure_auto_diet via unordered_next() when pi != 1, and add dedicated _pf variants (input_encoder_pf, emo/input_encoder_mo_pf, post_tf*_pf) folding color_divide with zero impact on pi == 1 DXILs, toggleable with WG_M_PF_FOLD=0.
…ut decode table and the encoder LDS (bit-exact) Follow-up to the Wave 1 levers (7b0f6a5), from the Wave 1 GPU A/B: T1.1 and T1.8 won, T1.2 / _pf regressed post_tf only because its VGPRs went 85 -> 96 (NW = 8: 2 workgroups per CU -> 1). - post_tf / post_tf_pf: one body per kernel (no inlined pi == 1 / pi != 1 copies). post_tf keeps b28679f's run-time pi == 1 branch at the store; _pf takes PiDiv + m1_scale unconditionally. The T1.2 cuts are now one switch each (WG_PO_*); the three per-lane hoists (staging row/column, horizontal roles, vertical first item) are left out of the NW = 8 kernels and the horizontal one of the NW = 4 kernels, everything else stays (exposure loads after the first staging loads, unrolled gather, QuadReadAcrossX display store, 2-chain reduced code, WG_PT_SMALL / WG_PT_INF, history base mask). RGA gfx1201, 0 spills: post_tf 96 -> 76, post_tf_pf 96 -> 77, post_tf4_dl 108 -> 83, post_tf4_dl_pf 90 -> 85, no v_and_b32 -8. Direct (form 3) kernels are unchanged. - T1.3 removed (f16lut_build_dec, the decode-table path of post.hlsl, wg_f16lut.hlsli / exposure.hlsl back to b28679f, runtime m_post_lut): it cost 5.5 us of build and saved nothing at pi = 1. - T1.5 reverted: input_encoder is back to b28679f's register-only A load (0 B LDS, 0 scratch); the WaveActiveAnyTrue(ec > 32752) guard and the _pf kernels stay. - kernel_sets.json regenerated (107 Model M / L kernels).
The PR is slower here in 9/9 interleaved rounds. Every round was +0.082 to +0.090 ms. These are unprofiled whole-frame GPU times at 1706x960 -> 2560x1440. Output exactnessOutput is byte-identical to main. I compared whole frames: every stage buffer plus the image, 3 frames, with each build run twice. Per-kernel timingThese are profiled per-frame GPU times, in milliseconds:
What ACO showsI compiled for gfx1201 without the card. There were no spills in either build. Likely source of the c64 regressionThe diff removes Setup and scopeI used synthetic Model M with raw synthetic weights and frames, on its default route, with Model L also built in for both builds. Both were built the same way. The PR head contains the post_tf alignment-mask hoist, scale_rgb store fold, Wave 1 levers, and Wave 1.5 post_tf/VGPR, f16lut and encoder LDS changes. Was removing |
…history pitch visibly 8-aligned (byte-identical) RADV review of #296: whole-frame GPU time was +0.087 ms against main because 7b0f6a5 dropped ,WG_LD_A16=1 from the @wg-kernel lines of swin_block_c64_nc (+0.024 ms, 4921 -> 5441 instructions on ACO) and d1p12/swin_block_c64_add_dec0_nc (+0.061 ms, 4122 -> 4578), which #294 had added for -101.6 us on RADV. Both lines have the flag again; no other alignment define differs from main. post.hlsl history_cr_span: the 24-bit multiplicand pitch & 0xffffff becomes pitch & 0xfffff8 (pitch is a multiple of 8, so the value is the same bits), a mask with the low three bits clear, so the product with it is visibly a multiple of 8 to a compiler that reads masks and not known bits. RGA gfx1201: post_tf 76 VGPRs / 4212 instructions and post_tf_pf 77 / 5337, both unchanged (same code, one scalar and moved), still no v_and_b32 -8.
Summary
Fixes a
+37.6 usWindows AMD DX12 regression introduced in #280 (e52f380) onw64/post_tf_f32_p12_diet_vsitwhile preserving provable 8-byte alignment for Linux RADV/ACO.Root Cause
Per-load
ld64_a8(a)/ld128_a8(a)(a & ~7u) across 66 load sites inclean/dx12/kernels/post.hlslcaused the Windows AMD DX12 shader compiler to emit79v_and_b32instructions (up from13), prevented immediate offset folding, and increasedUSED_VGPRsfrom85 -> 96.Fix
Hoist the
& ~7umask once onto the 256-byte-aligned scalar base pointers (A8 & ~7u,hist_prev & ~7u, andb0 & ~7u) so every derived 8-byte offset remains provably 8-byte aligned for RADV/ACO while cuttingv_and_b32back down (79 -> 17) and restoringUSED_VGPRs(96 -> 85) on Windows AMD DX12.Verification (RX 9070 XT
gfx1201, 1440p Quality1706x960 -> 2560x1440)w64/post_tf_f32_p12_diet_vsit):0.5996 ms -> 0.5583 ms(-41.3 us, matching v0.6.50.5587 ms).test_post_tf_align,check_no_dev_diagnostics.py,test_model_select, andtools/ci/check_line_endings.pyall pass.